package com.xinlu.user.action;

import com.xinlu.derek.common.BaseAction;
import com.xinlu.derek.common.BaseForm;
import com.xinlu.persistence.Users;
import com.xinlu.user.bo.UsersBo;
import com.xinlu.user.dao.MD5Util;
import com.xinlu.user.form.QkmmForm;

public class XgmmAction extends BaseAction {

	QkmmForm fr = new QkmmForm();
	private UsersBo usersBo;

	public void setUsersBo(UsersBo usersBo) {
		this.usersBo = usersBo;
	}

	@Override
	public String doExecute() throws Exception {
		return null;
	}

	@Override
	public void formInit() {
	}

	@Override
	public BaseForm getModel() {
		return fr;
	}

	/**
	 * 加载页面
	 * 
	 * @return
	 */
	public String loadPage() {
		fr.setXmm("");
		return "xgmm";
	}

	/**
	 * 修改密码
	 * 
	 * @return
	 * @throws Exception
	 */
	public String changePwd() throws Exception {
		Users crtUser = (Users) getSession().getAttribute("userinfo");
		crtUser = this.usersBo.loadUser(crtUser.getUsername());
		if (!MD5Util.encodePassword(fr.getJmm()).toLowerCase().equals(crtUser.getUserpass().toLowerCase())) {
			throw new Exception("密码错误");
		}

		crtUser.setUserpass(MD5Util.encodePassword(fr.getXmm()));
		usersBo.update(crtUser);
		
		return "operSuccess";
	}

	public void setFr(QkmmForm fr) {
		this.fr = fr;
	}

}
